package ttsolver.constraints;

import ttsolver.input.Train;

public class ConsSpaceTime extends DefaultConstraint {

	private Train train1;
	private Train train2;
	private int milepost;
	private int id;

	public ConsSpaceTime() {
		super(ConstraintType.CONS_SPACE_TIME);
	}

	public ConsSpaceTime(Train train1, Train train2, int milepost, int id) {
		super(ConstraintType.CONS_SPACE_TIME);
		this.train1 = train1;
		this.train2 = train2;
		this.milepost = milepost;
		this.id = id;
	}
		
	public Train getTrain1() {
		return train1;
	}

	public void setTrain1(Train train1) {
		this.train1 = train1;
	}

	public Train getTrain2() {
		return train2;
	}

	public void setTrain2(Train train2) {
		this.train2 = train2;
	}

	public int getMilepost() {
		return milepost;
	}

	public void setMilepost(int milepost) {
		this.milepost = milepost;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((train1 == null) ? 0 : train1
						.getId().intValue());
		result = prime
				* result
				+ ((train2 == null) ? 0 : train2
						.getId().intValue());
		result = prime * result + milepost;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		ConsSpaceTime other = (ConsSpaceTime) obj;

		if (train1 == null) {
			if (other.train1 != null)
				return false;
		} else if (!train1.equals(other.train1)) {
			return false;
		}
		
		if (train2 == null) {
			if (other.train2 != null)
				return false;
		} else if (!train2.equals(other.train2)) {
			return false;
		}

		if (milepost != other.milepost) {
			return false;
		}
		
		if (id != other.id) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		String s = "";
		s += (train1 != null) ? train1.getId() : "N/A";
		s += (train2 != null) ? "," + train2.getId() : "N/A";
		s += "," + milepost;
		if(id == 1)
			return "Space_Time_1_(" + s + "):\n";
		else
			return "Space_Time_2_(" + s + "):\n";
	}

}
